/*
 * Copyright 2020-2030 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
*/
package com.gitee.minimalismstyle.fresh.simple.api.service

import com.alicp.jetcache.anno.CacheInvalidate
import com.alicp.jetcache.anno.Cached
import com.gitee.minimalismstyle.fresh.common.api.annotation.ControllerFeignClient
import com.gitee.minimalismstyle.fresh.common.core.const.CacheConst
import com.gitee.minimalismstyle.fresh.common.core.domain.QueryBody
import com.gitee.minimalismstyle.fresh.common.core.domain.QueryParams
import com.gitee.minimalismstyle.fresh.common.core.domain.R
import com.gitee.minimalismstyle.fresh.common.core.domain.Simple
import com.gitee.minimalismstyle.fresh.common.data.commons.service.LongModelBaseService
import com.gitee.minimalismstyle.fresh.simple.api.config.SimpleApiConst
import com.gitee.minimalismstyle.fresh.simple.api.model.CopySimpleListFormFields
import com.gitee.minimalismstyle.fresh.simple.api.model.SimpleList
import com.gitee.minimalismstyle.fresh.simple.api.model.SimpleListFormFields
import com.gitee.minimalismstyle.fresh.simple.api.model.SimpleSqlParams
import io.swagger.annotations.Api
import org.springframework.web.bind.annotation.*

/**
 * 列表定义业务接口
 * @author maoxiaodong
*/
@Api(value = "simpleList", tags = ["列表定义接口"])
@ControllerFeignClient(serviceId = SimpleApiConst.SERVICE_ID, ctx =SimpleApiConst.CTX, path = "/simpleList")
interface SimpleListService: LongModelBaseService<SimpleList>{

    @CacheInvalidate(name="simpleListCache-", key="#simpleListFormFields.code")
    @PutMapping("saveSimpleListFormFields")
    fun saveSimpleListFormFields(@RequestBody simpleListFormFields: SimpleListFormFields): R<SimpleListFormFields>

    @PutMapping("copySimpleListFormFields")
    fun copySimpleListFormFields(@RequestBody copySimpleListFormFields: CopySimpleListFormFields): R<SimpleListFormFields>

    @Cached(name="simpleListCache-", key="#code", expire = CacheConst.CACHE_DEFAULT_EXPIRE)
    @GetMapping("findSimpleListFormFieldsByCode/{code}")
    fun findSimpleListFormFieldsByCode(@PathVariable code: String): R<SimpleListFormFields>

    @GetMapping("simpleSqlParams/{code}")
    fun getSimpleSqlParams(@PathVariable code: String, simple: Simple) : R<SimpleSqlParams>

    @GetMapping("findByCode/{code}")
    fun findByCode(@PathVariable code: String): R<SimpleList>

    @GetMapping("data/{code}")
    fun findDataPageByCode(@PathVariable code: String, queryParams: QueryParams<Simple>): R<QueryBody<Simple>>

    @PostMapping("data/{code}")
    fun findDataByCode(@PathVariable code: String, @RequestBody queryParams: QueryParams<Simple>): R<QueryBody<Simple>>
}